'''
Created on 19/04/2010

@author: Mar
'''
class PCB:
     
    def __init__(self, aProgram):
        self.program = aProgram
        self.state = "Nuevo"
        self.pc = 0
        self.priority = aProgram.getPriority()
        self.totalQuantum = self.getTotalQuantum()
        self.instToExecute = 0
        self.parent = None
        self.isChild = False
        
        
        
    def setParent (self, aPCB):
        self.parent = aPCB
    
    def getParent (self):
        return self.parent
           
    def setChild(self):
        self.isChild = True
    
    def getInstToExectute(self):
        return self.instToExecute
    
    def setInstToExecute(self, cant):
        self.instToExecute = cant
        
        
    def __le__(self,anOtherPCB):
        return (self.priority<= anOtherPCB.getPriority())
            
    def __lt__(self,anOtherPCB):
        return self.priority<anOtherPCB.getPriority()
    
    def getPC(self):
        return self.pc
    
    def setPC(self, x):
        self.pc=x
    
    def totalInstructions(self):
        return (self.program.getInstructions().__len__())    
      
    def isThereNextInst(self):
        return (self.getPC()< self.totalInstructions())
    
    def getPriority(self):
        return self.priority
    
    def getProgram(self):
        return self.program
    
    def getCurrentInstruction(self):
        return self.getProgram().getInstructions().__getitem__(self.getPC())
    
    def getCurrentInstructionType(self):
        return self.getCurrentInstruction().getType()
    
    def getCurrentInstructionTime(self):
        return self.getCurrentInstruction().getTime()
    
    def toReady(self):
        self.state = "Ready"
        
    def advance(self):
        self.setPC(self.getPC() + 1)
        
    def toFinished(self):
        self.state = "finished"
        
    def isFinished(self):
        return (self.state == "finished")
    
    def getTotalQuantum(self):
        total = 0
        for inst in self.program.getInstructions():
            total = inst.getTime() + total
        return total

    
    def getNextInstTime(self):
        if (self.isThereNextInst()):
            return (self.getProgram().getInstructions().__getitem__(self.getPC()+1).getTime())
            
            
            
            
            
            
            
            